  // 1写入验证码
  $('[name="javascrit:;"]').html(getVC()).click(function(){
    $('[name="javascrit:;"]').html(getVC());
})
// 2, 用户名验证
// 账号input 失去焦点触程序
$('[name="nameIpt"]').blur(function(){
    selectName();
})
// 3，注册验证密码和 验证码
$('button').click(function(){
    setRegister();
})


   
async function selectName(){
let name = $('[name="nameIpt"]').val();

const res = await myPromiseAjax('../server/goods_select.php' , 'post' , {userName:name} , 'json');

console.log(res);
if(res.code === 1){
    $('[name="nameSpan"]').html('<span style="color:blue">账号名字可以使用</span>');
}else if(res.code === 0 ){
    $('[name="nameSpan"]').html('<span style="color:red">账号名字重复,请重新输入</span>');
}
}

async function setRegister(){
 let name = $('[name="nameIpt"]').val();
 let pw1 = $('[name="pwd1"]').val();
 let pw2 = $('[name="pwd2"]').val();
 let vc = $('[name="vcIpt"]').val();

//  判断密码是否一致
 if(pw1 !== pw2){
    
    $('[name="pwdSpan2"]').html('<span style="color:red">两次密码不一致请重新检查</span>');
   
    $('[name="javascrit:;"]').html(getVC());

    return ;

 }else if(pw1 === pw2){
    $('[name="pwdSpan2"]').html('');
 }

//  判断验证码是否一致
if(vc.toLowerCase() !==  $('[name="javascrit:;"]').html().toLowerCase()){
    $('[ name="vc"]').html('<span style="color:red">验证码错误</span>');
    $('[name="vcIpt"]').val('');
    $('[name="javascrit:;"]').html(getVC());
    return ;
}else if(vc.toLowerCase() ===  $('[name="javascrit:;"]').html().toLowerCase()){
    $('[ name="vc"]').html('');
}


const res = await myPromiseAjax( '../server/goods_register.php' , 'post' , {userName:name , userPwd:pw1 } , 'json' );

if(res.code === 1){
    let time = 5;
    $('[name="result"]').html(`<span style="color:blue">恭喜你注册成功,${time}秒后跳转首页，<a href="./login.html">点击跳转登录页面</a></span>`);

    let t =  setInterval(()=>{
        time--;
        $('[name="result"]').html(`<span style="color:blue">恭喜你注册成功,${time}秒后跳转首页，<a href="./login.html">点击跳转登录页面</a></span>`);


        if(time === 1){
        
        clearInterval(t);

        window.location.href = './index.html';
    }
    } , 1000)
   

}
}
